package com.thor.palmmall.rest.order;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.thor.commons.util.StringUtil;

public class OrderDateUtil {
	public static final String FORMATUTC = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
	public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";  
	
	public static Date stringToDate(String date,String formatStr) {
		if(StringUtil.isNullOrBlank(date)){
			return null;
		}
		SimpleDateFormat format = new SimpleDateFormat(formatStr);
		try {
			return  format.parse(date);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
	}
	
	public static String parseUTC(String date) {
		if(StringUtil.isNullOrBlank(date)){
			return null;
		}
		return parseToString(stringToDate(date,DATE_FORMAT),FORMATUTC);
	}
	
	public static String parseDate(String date) {
		if(StringUtil.isNullOrBlank(date)){
			return null;
		}
		return parseToString(stringToDate(date,FORMATUTC),DATE_FORMAT);
	}
	public static String parseToString(Date date,String fmat){
		SimpleDateFormat format = new SimpleDateFormat(fmat);
		return  format.format(date);
	}
	
	public static void main(String args[]){
		
		Date date = new Date();
		SimpleDateFormat format = new SimpleDateFormat(FORMATUTC);
		String da1 = "2017-06-21 10:47:13";
		
	}
}
